package com.example.lyl.yuejian.view.home;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.lyl.yuejian.R;
import com.example.lyl.yuejian.bean.MatchDetialBean;
import com.example.lyl.yuejian.net.NetTool;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;

public class MatchDetialActivity extends AppCompatActivity {

    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.match_iv)
    ImageView matchIv;
    @BindView(R.id.bsmc_tv)
    TextView bsmcTv;
    @BindView(R.id.jj_tv)
    TextView jjTv;
    @BindView(R.id.dd_tv)
    TextView ddTv;
    @BindView(R.id.jg_tv)
    TextView jgTv;
    @BindView(R.id.bssj_tv)
    TextView bssjTv;
    @BindView(R.id.gm_btn)
    Button gmBtn;
    private int gid;
    private String adress;
    private int gprice;
    private String gname;
    private String gpic;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_match_detial);
        ButterKnife.bind(this);


        gid = getIntent().getIntExtra("gid", 0);

        toolbar.setTitle("比赛详情");
        setSupportActionBar(toolbar);
        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.setDisplayHomeAsUpEnabled(true);
        }

        NetTool.getInstance().getApi()
                .matchDetialRequest(gid)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<MatchDetialBean>() {
                    @Override
                    public void accept(MatchDetialBean matchDetialBean) throws Exception {
                        Glide.with(MatchDetialActivity.this)
                                .load("http://" + matchDetialBean.getData().getGpic()).placeholder(R.mipmap.lunbo2).into(matchIv);
                        gpic = "http://" + matchDetialBean.getData().getGpic();
                        bsmcTv.setText("比赛名称:  " + matchDetialBean.getData().getGname());
                        bssjTv.setText("比赛时间:  " + matchDetialBean.getData().getGtime());
                        jjTv.setText("简介:  " + matchDetialBean.getData().getGintro());
                        adress = matchDetialBean.getData().getGplace();
                        jgTv.setText("价格:  " + matchDetialBean.getData().getGprice());
                        gprice = matchDetialBean.getData().getGprice();
                        ddTv.setText("地点:  " + matchDetialBean.getData().getGplace());
                        gname = matchDetialBean.getData().getGname();
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {

                    }
                });
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                finish();
                break;
        }
        return true;
    }

    @OnClick(R.id.gm_btn)
    public void onViewClicked() {
        Intent intent = new Intent();
        intent.putExtra("adress",adress);
        intent.putExtra("gid",gid);
        intent.putExtra("gname",gname);
        intent.putExtra("gprice",gprice);
        intent.putExtra("gpic",gpic);
        intent.setClass(MatchDetialActivity.this,MatchOrderActivity.class);
        startActivity(intent);
        finish();
    }
}
